﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>牛仔对决</title>
    <meta name="viewport" id="WebViewport"
          content="width=720px,initial-scale=1,target-densitydpi=device-dpi,minimum-scale=0.3,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <script src="libs/easeljs.min.js"></script>
    <script src="libs/tweenjs-0.5.1.min.js"></script>
    <script src="libs/movieclip-0.7.1.min.js"></script>
    <script src="libs/preloadjs-0.4.1.min.js"></script>
    <!-- <script src="libs/rem.js"></script> -->
    <script src="index.js?and=2223"></script>
    <script src="run.js"></script>
    <script src="libs/jweixin-1.0.0.js"></script>
    <script src="js/jquery-1.7.1.min.js"></script>
    <script src="js/vue.js"></script>

    <style type="text/css">
        <!--
        @viewport {
            zoom: 1.0;
            width: 720px;
        }

        @-ms-viewport {
            width: 720px;
            zoom: 1.0;
        }

        body {
            background-color: #ffffff;
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
            background-size: 100% auto;
            background-image: url(images/_1.jpg);
            background-repeat: repeat-y
        }

        body, td, th {
            color: #520000;
            font-size: 20px;
            font-family: "微软雅黑";
        }

        .tip_mask {
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: 100;
            text-align: center;
        }
        .mask_bg {
            width: 80%;
            z-index: 10;
            margin-top: 20%;
            display: inline-block; 
            vertical-align: middle;
        }

        -->
    </style>
    <script>
        /////////////////接口代码在页面最下面

        var bfb
        if (screen.width < 720) {
            document.getElementById('WebViewport').setAttribute('content', 'width=720px,initial-scale=' + screen.width / 720 + ',target-densitydpi=device-dpi,minimum-scale=0.3,maximum-scale=1,user-scalable=no');
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////

    </script>

</head>

<body onLoad="autoPlayAudio1();" style="background-color:#ffffff; text-align:center">


<div style="width:100%; height:100%; position:absolute;display:; z-index:200000000; ;" id="fmv">
    <iframe runat="server" src="/cowboy/loading/index.html" name="myFrame" frameborder="no" border="0"
            marginwidth="0" marginheight="0" scrolling="y" allowtransparency="yes" id="loaderdiv"
            style="width:100%; height:100%; overflow-x : hidden; background-color:#ffffff" onload=""></iframe>
</div>


<canvas id="canvas" width="720" height="100%"
        style=" width:100%; height:100%;  position:fixed; left:0px; top:0px;"></canvas>
<div id="ws" style="display:none">
    <button>enter</button>
    <br> <br>
    <button disabled="disabled">Close</button>
    <button>Open</button>
    <div>
        用户余额
        <br>

        可以玩吗：
        <br></div>
</div>
<div id="music">

</div>

<div class="tip_mask" style="display: none;" >
    <img src="images/mask_bg.png" id="download" class="mask_bg">
</div>

<audio src="mp3/bg.mp3" preload="preload" id="myaudio" loop autoplay="autoplay"></audio>
<audio src="mp3/kong.mp3" preload="preload" id="kong"></audio>
<audio src="mp3/qiang.mp3" preload="preload" id="qiang"></audio>

<audio src="mp3/zhuan.mp3" preload="preload" id="zhuan" loop></audio>

<script>

    $("#download").click(function (e) {
        e.stopPropagation()
        if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
            window.location.href = "http://itunes.apple.com/app/id1324911162?mt=8"
        } else {
            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.canfu.pcg"
        }
    })

    $(".tip_mask").click(function(){
        $(".tip_mask").hide()
    })


    var httpHost = "game.zbswzn.cn";
    var host = "channel.kxqianbao.com";
    // var httpHost = "10.168.1.182:8085";
    // var host = "10.168.1.182";


    var musicobj = document.getElementById('myaudio')
    var musicobj2 = document.getElementById('kong')
    var musicobj3 = document.getElementById('qiang')
    var musicobj4 = document.getElementById('zhuan')

    function doPay() {
        $("#download").show();
    }


    function doClose() {
        /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) ? closeGame() : native.closeGame()
    }


    var getini;

    function getinfo() {
        var url = window.document.location.href.toString();
        var u = url.split("?");
        if (typeof(u[1]) == "string") {
            var get = {};
            get['domain'] = u[0];
            u = u[1].split("&");
            for (var i in u) {
                var j = u[i].split("=");
                get[j[0]] = j[1];
            }
            return get;
        }
        else {
            return {};
        }
    }


    function getParam() {
        if (!getini) getini = getinfo();
        return getini;
    }

    var param = getParam();

    var phone = param.phone;
    var channel = param.channel;
    var channelId = param.channelId;


    function createNewUser() {
        $.ajax({
            url: 'http://' + httpHost + '/user/noAuth/createAndLogin',
            type: 'post',
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({'phone': phone, 'channelId': channelId, 'channel': channel}),//这里使用json对象
            success: function (data) {
                param.token = data.data
                if (!param.token || param.token.length <= 0) {
                    //没有获取到
                    doClose();
                }
            },
            fail: function () {
                //调用约定方法，关闭游戏
                doClose();
            }
        });
    }


    if (phone && phone.length == 11 && channel && channel.length > 0) {
        createNewUser();
    }


    function autoPlayAudio1() {
        init()
    }


    var tokens = param.token
    if (!tokens || tokens.length <= 0) {
        doClose();
    }

    //////////////////////////////////websocked
    function payfun() {//////////////////////////////////充值调用
        // showPay();
        doPay();
    }

    function backfuns() {
        doClose();
    }


    function loadlist() {
        show('/cowboy/list/index.html?token=' + tokens)
    }


    var websocket = null;

    var canplay = true;

    var obj22

    function jh(obj2) {
        obj22 = obj2

        //可以反复赋值，昵称/ID/奖励
        var wsVue = new Vue({
            el: '#ws',
            data: {
                user: {},
                msg: "welcome to my websocket...<br/>",
                opened: false,
                data: [],
                result: {}
            },
            mounted: function () {
                initWs();
            }
        });


        function initWs() {
            if ('WebSocket' in window) {
                websocket = new WebSocket("ws://" + host + "/nz");
            } else {
                alert('Sorry, websocket not supported by your browser.')
            }

            //Error callback
            websocket.onerror = function () {

            };

            //socket opened callback
            websocket.onopen = function (event) {

                var message = {messageType: 1, request: {userToken: tokens}}
                websocket.send(JSON.stringify(message));

                var message = {messageType: 3, request: {userToken: tokens}}
                websocket.send(JSON.stringify(message));

            }

            //message received callback
            websocket.onmessage = function (event) {
                setMessageContent(JSON.parse(event.data));
            }

            //socket closed callback
            websocket.onclose = function () {
                console.log("服务中断，开始重连。。。。")
                setTimeout(function () {
                    initWs();
                }, 1000)
            }

            //when browser window closed, close the socket, to prevent server exception
            window.onbeforeunload = function () {
                websocket.close();
            }
        }

        //update message to vue and then in div
        function setMessageContent(content) {
            if (content.type == 4) {
                obj22.appspr.dm.ttt.text = content.money
            }
            if (content.type == 2) {
                canplay = content.canPlay
                canplay = true;
                obj22.appspr.settxtfun(content)
                if (canplay == true) {
                    obj22.appspr.timebar.num = content.leftTime
                } else {
                    obj22.appspr.timebar.num = -1
                }
            }
            if (content.type == 5) {
                wsVue.user = content.request;
            }

            if (content.type == 6 && content.code == 501) {
                doPay();
                return
            }

            if (content.type == 7) {
                obj22.appspr.timebar.ttt.text = '决斗中'
                obj22.appspr.timebar.num = -1
                obj22.appspr.losemc.alpha = 0
                canplay = false
                winid = content.selfWin
                if (winid) {
                    //查询用户余额
                    setTimeout(function () {
                        var message = {messageType: 3, request: {userToken: tokens}}
                        websocket.send(JSON.stringify(message));
                    }, 4000)
                }

                winnum = content.money

                if (content.index == 0) {
                    if (content.win) {
                        obj22.jg = 1

                    } else {
                        obj22.jg = 0
                    }
                    obj22.appspr.leftbtn.gotoAndPlay(20);
                } else {
                    if (content.win) {
                        obj22.jg = 1

                    } else {
                        obj22.jg = 0
                    }
                    obj22.appspr.rightbtn.gotoAndPlay(20);
                }
            }
        }


    }

    var winid = -1
    var winnum = 0

    function stakefun(group, stake, mm) {
        var message = {
            messageType: 5,
            request: {
                userToken: tokens,
                money: mm,
                groupId: group,
                stakeId: stake
            }
        }
        websocket.send(JSON.stringify(message));
    }


    function endfun1() {
        var d = document.getElementById('fmv');
        d.style.display = "none";
        document.getElementById("loaderdiv").src = '123.htm'
    }


    function show(urll) {
        document.getElementById("loaderdiv").src = urll
        document.getElementById("loaderdiv").scrolling = "y"
        view()
    }

    function view() {
        var d = document.getElementById('fmv');
        d.style.display = "block";
    }


    function playsound() {
        musicobj = document.getElementById('myaudio')
        musicobj.load();
        musicobj.play();
    }


</script>

</body>
</html>